//
//  UIView+EXtension.h
//  ZPIOSEducation
//
//  Created by 李伟 on 2016/11/23.
//  Copyright © 2016年 liwei. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <objc/runtime.h>

typedef NS_ENUM(NSInteger, ZPAnimationType)
{
    ZPAnimationOpen,// 动画开启
    ZPAnimationClose// 动画关闭
};

@interface UIView (EXtension)
// width
@property (nonatomic) CGFloat xj_width;
// height
@property (nonatomic) CGFloat xj_height;
// x
@property (nonatomic) CGFloat xj_x;
// y
@property (nonatomic) CGFloat xj_y;
// left
@property (nonatomic) CGFloat xj_left;
// right
@property (nonatomic) CGFloat xj_right;
// top
@property (nonatomic) CGFloat xj_top;
// bottom
@property (nonatomic) CGFloat xj_bottom;
// center-X
@property (nonatomic) CGFloat xj_centerX;
// center-Y
@property (nonatomic) CGFloat xj_centerY;
// screenX
@property (readonly, nonatomic) CGFloat xj_screenX;
// screenY
@property (readonly, nonatomic) CGFloat xj_screenY;
// screenFrame
@property (readonly, nonatomic) CGRect  xj_screenFrame;
// screenViewX
@property (readonly, nonatomic) CGFloat xj_screenViewX;
// screenViewY
@property (readonly, nonatomic) CGFloat xj_screenViewY;
// orientationWidth
@property (readonly, nonatomic) CGFloat xj_orientationWidth;
// orientationHeight
@property (readonly, nonatomic) CGFloat xj_orientationHeight;
// frameorigin
@property (nonatomic) CGPoint xj_frameorigin;
// frameorigin
@property (nonatomic) CGSize  xj_framesize;
// tagStr
@property (copy, nonatomic) NSString *tagStr;

/**
 * Finds the first descendant view (including this view) that is a member of a particular class.
 */
- (UIView*)descendantOrSelfWithClass:(Class)cls;

/**
 * Finds the first ancestor view (including this view) that is a member of a particular class.
 */
- (UIView*)ancestorOrSelfWithClass:(Class)cls;

/**
 * Removes all subviews.
 */
- (void)removeAllSubviews;

/**
 * Calculates the offset of this view from another view in screen coordinates.
 *
 * otherView should be a parent view of this view.
 */
- (CGPoint)offsetFromView:(UIView*)otherView;


/**
 *  裁剪 view 的圆角
 *
 *  @param rectCorner 四个角的方向
 */
-(void)clipRectCornerWithDirection:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius;


- (BOOL)isShowingOnKeyWindow;



#pragma mark - <动画相关>
/**
 *  在某个点添加动画
 *
 *  @param point 动画开始的点
 */
- (void)zp_addAnimationAtPoint:(CGPoint)point;

/**
 *  在某个点添加动画
 *
 *  @param point          动画开始的点
 *  @param type           动画的类型
 *  @param animationColor 动画的颜色
 */
- (void)zp_addAnimationAtPoint:(CGPoint)point WithType:(ZPAnimationType)type withColor:(UIColor *)animationColor;

/**
 *  在某个点添加动画
 *
 *  @param point          动画开始的点
 *  @param type           动画的类型
 *  @param animationColor 动画的颜色
 *  @param completion     动画结束后的代码快
 */
- (void)zp_addAnimationAtPoint:(CGPoint)point WithType:(ZPAnimationType)type withColor:(UIColor *)animationColor completion:(void (^)(BOOL finished))completion;

/**
 *  在某个点添加动画
 *
 *  @param point          动画开始的点
 *  @param duration       动画时间
 *  @param type           动画的类型
 *  @param animationColor 动画的颜色
 *  @param completion     动画结束后的代码快
 */
- (void)zp_addAnimationAtPoint:(CGPoint)point WithDuration:(NSTimeInterval)duration WithType:(ZPAnimationType) type withColor:(UIColor *)animationColor completion:(void (^)(BOOL finished))completion;

@end
